<!--
 * @Author: happyjing happyjing5@sina.cn
 * @Date: 2024-04-03 20:30:40
 * @LastEditors: 淹死De鱼5 happyjing5@sina.cn
 * @LastEditTime: 2024-04-24 01:17:39
 * @FilePath: \vue-ruoyi-drp\src\views\center\member\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="介绍人" prop="memberPid">
        <el-input
          v-model="queryParams.memberPid"
          placeholder="请输入介绍人(上级)ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="用户账号" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入用户账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="memberNickName">
        <el-input
          v-model="queryParams.memberNickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户邮箱" prop="memberEmail">
        <el-input
          v-model="queryParams.memberEmail"
          placeholder="请输入用户邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="memberPhone">
        <el-input
          v-model="queryParams.memberPhone"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="审核状态" prop="numberStatus">
        <el-select v-model="queryParams.numberStatus" placeholder="审核状态" clearable>
          <el-option
            v-for="dict in dict.type.member_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="信息审核" prop="numberStatus">
        <el-select v-model="queryParams.mbExpIsEdit" placeholder="信息审核" clearable>
          <el-option
            label="未审核"
            value="1"
          />
          <el-option
            label="已通过"
            value="0"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['center:member:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['center:member:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['center:member:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['center:member:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="memberList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="手机号码" align="center" prop="memberPhone"  width="120" />
      <el-table-column label="姓名" align="center" prop="drpMemberExpOne.mbExpName" />
      <el-table-column label="用户昵称" align="center" prop="memberNickName" />
      <el-table-column label="分享码" align="center" prop="drpMemberExpOne.mbExpShareCode" />
      <!-- <el-table-column label="用户类型" align="center" prop="memberType" /> -->
      <!-- <el-table-column label="用户邮箱" align="center" prop="memberEmail"  width="180" /> -->
      
      <el-table-column label="用户账号" align="center" prop="memberName" />
      <el-table-column label="介绍人" align="center">
        <template slot-scope="scope">
          {{ scope.row.memberPid === 0?'平台': scope.row.memberPname}}
        </template>
      </el-table-column>
      <!-- <el-table-column label="用户性别" align="center" prop="numberSex" /> -->
      <el-table-column prop="numberSex" label="性别" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_sex_status" :value="scope.row.numberSex"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="头像地址" align="center" prop="numberAvatar" /> -->
      <el-table-column label="头像地址" align="center" prop="numberAvatar" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.numberAvatar" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="帐号状态" align="center" prop="numberStatus" /> -->
      <!-- <el-table-column label="审核状态" align="center" prop="numberStatus">
        <template slot-scope="scope">
            <el-tag
            :type="['primary','success', 'error'][scope.row.numberStatus]"
            disable-transitions>{{ ['审核中','已审核','审核未通过'][scope.row.numberStatus] }}</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column label="是否诉讼" align="center" prop="numberStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.member_status" :value="scope.row.numberStatus"/>
        </template>
      </el-table-column>

      
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="更新时间" align="center" prop="updateTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="账号状态" align="center" prop="numberDelFlag" width="100">
        <template slot-scope="scope">
          <!-- <el-tag
            :type="scope.row.numberStatus === '0' ? 'primary' : 'success'"
            disable-transitions>{{scope.row.numberStatus === '0' ? '审核中' : '已审核'}}</el-tag> -->
            <!-- <el-tag
            :type="['primary','success'][scope.row.numberDelFlag]"
            disable-transitions>{{ ['正常','冻结'][scope.row.numberDelFlag] }}</el-tag> -->
            <el-switch
              v-model="scope.row.numberDelFlag"
              active-value="0"
              inactive-value="1"
              active-color="#13ce66"
              @change="(val) => {changeSwitchFlag(val, scope.row)}"
              inactive-color="#ff4949">
            </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['center:member:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['center:member:remove']"
          >删除</el-button>
          <el-button
            v-if="scope.row.numberStatus !== '1'"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="openMemberVisible(scope.row)"
          >审核</el-button>
          <el-button
            v-if="scope.row.drpMemberExpOne.mbExpIsEdit === '1'"
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="openCheckEditHandle(scope.row)"
          >头像审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="85px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="介绍码" prop="memberPidCode">
          <el-input v-model="form.memberPidCode" placeholder="请输入介绍码" />
          </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="drpMemberExpOne.mbExpName">
              <el-input v-model="form.drpMemberExpOne.mbExpName" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="昵称" prop="memberNickName">
              <el-input v-model="form.memberNickName" placeholder="请输入用户昵称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="numberSex">
              <el-select v-model="form.numberSex" placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.sys_sex_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <el-form-item label="邮箱" prop="memberEmail">
              <el-input v-model="form.memberEmail" placeholder="请输入用户邮箱" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号" prop="memberPhone">
              <el-input v-model="form.memberPhone" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <el-form-item label="身份证号" prop="drpMemberExpOne.mbExpIdNumber">
              <el-input v-model="form.drpMemberExpOne.mbExpIdNumber" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <el-form-item label="密码" prop="numberPassword">
              <el-input v-model="form.numberPassword" placeholder="请输入密码" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="单位" prop="drpMemberExpOne.mbExpUnit">
              <el-input v-model="form.drpMemberExpOne.mbExpUnit" placeholder="请输入单位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="头像" prop="numberAvatar">
              <!-- <el-input v-model="form.numberAvatar" placeholder="请输入" /> -->
              <image-upload v-model="form.numberAvatar" :limit="1" listType="text" :isShowTip="false" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="身份证正反照片" prop="drpMemberExpOne.mbExpIdImage">
              <image-upload v-model="form.drpMemberExpOne.mbExpIdImage" listType="text" :isShowTip="false" :limit="2" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <checkMember :visible.sync="openCheck" :record="recordCheckInfo" @cancelHandle="getList" />
    <checkEdit :visible.sync="openCheckEdit" :id="recordId" @cancelHandle="getList" />
  </div>
</template>

<script>
import { listMember, getMember, delMember, addMember, updateMember } from "@/api/center/member";
import checkMember from "./components/checkMember.vue";
import checkEdit from "./components/checkEdit.vue";
export default {
  name: "Member",
  dicts: ['member_status', 'sys_sex_status'],
  components: {
    checkMember,
    checkEdit
  },
  data() {
    return {
      // 打开审核修改
      openCheckEdit: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedDrpMemberExp: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员信息管理表格数据
      memberList: [],
      // 用户扩展属性表格数据
      drpMemberExpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 会员遮罩层
      openCheck: false,
      // 会员审核传入参数
      recordCheckInfo: {},
      // 审核头像传入的参数
      recordId: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberPid: null,
        memberPidCode: null,
        memberName: null,
        memberNickName: null,
        memberType: null,
        memberEmail: null,
        memberPhone: null,
        numberSex: null,
        numberAvatar: null,
        numberPassword: null,
        numberStatus: null,
        numberDelFlag: null,
        numberLoginIp: null,
        numberLoginDate: null,
        createAt: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        mbExpIsEdit: null
      },
      // 表单参数
      form: {
        drpMemberExpOne: {}
      },
      // 表单校验
      rules: {
        memberPidCode: [
          { required: true, message: "介绍码不能为空", trigger: "blur" }
        ],
        memberName: [
          { required: true, message: "用户账号不能为空", trigger: "blur" }
        ],
        memberNickName: [
          { required: true, message: "用户昵称不能为空", trigger: "blur" }
        ],
        memberPhone: [
        { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        mbExpIdNumber: [
        { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        numberPassword: [
        { required: true, message: "密码不能为空", trigger: "blur" }
        ],
        memberEmail: [
          { required: true, message: "邮箱不能为空", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        'drpMemberExpOne.mbExpIdNumber': [
        { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        'drpMemberExpOne.mbExpIdImage': [
         { required: true, message: "身份证照片不能为空", trigger: "blur" }
        ],
        'drpMemberExpOne.mbExpUnit': [
         { required: true, message: "单位不能为空", trigger: "blur" }
        ],
        numberSex: [
         { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        'drpMemberExpOne.mbExpName': [
        { required: true, message: "姓名不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 改变会员账号状态
    changeSwitchFlag(val,record) {
      console.log(record)
      const postData = {
        userId: record.userId,
        numberDelFlag: val
      }
      updateMember(postData).then((response) => {
        if (response.code != 200) {
          this.$modal.msgError("更改错误请联系管理员");
          record.numberDelFlag = (1 - val) + ''
        } else {
          this.$modal.msgSuccess("修改成功");
        }
      })
      
    },
    // cancelCheckMember
    cancelCheckMember(status) {
      this.openCheck = status
      this.getList();
    },
    // 打开会员审批
    openMemberVisible(record) {
      this.recordCheckInfo = record
      this.openCheck = true
    },
    // 打开头像审核
    openCheckEditHandle (record) {
      this.openCheckEdit = true
      this.recordId = record.userId
    },
    /** 查询会员信息管理列表 */
    getList() {
      this.loading = true;
      listMember(this.queryParams).then(response => {
        this.memberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        memberPid: null,
        memberPidCode: null,
        memberName: null,
        memberNickName: null,
        memberType: null,
        memberEmail: null,
        memberPhone: null,
        numberSex: null,
        numberAvatar: null,
        numberPassword: null,
        numberStatus: null,
        numberDelFlag: null,
        numberLoginIp: null,
        numberLoginDate: null,
        createAt: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        drpMemberExpOne: {
          mbExpName: null,
          mbExpIdNumber: null,
          mbExpIdImage: null,
          mbExpUnit: null
        }
      };
      this.drpMemberExpList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids
      getMember(userId).then(response => {
        this.form = response.data;
        this.drpMemberExpList = response.data.drpMemberExpList;
        this.open = true;
        this.title = "修改会员信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // this.form.drpMemberExpList = this.drpMemberExpList;
          if (this.form.userId != null) {
            updateMember(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMember(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$modal.confirm('是否确认删除会员信息管理编号为"' + userIds + '"的数据项？').then(function() {
        return delMember(userIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('center/member/export', {
        ...this.queryParams
      }, `member_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
